﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using PowerTestController.ViewModes;
using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO.Ports;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace PowerTestController.Models
{
    public partial class MainModel : ObservableObject
    {
        public MainModel()
        {
        }

        #region 属性

        //[ObservableProperty]
        //private SerialPortModel spModel;

        [ObservableProperty]
        private ObservableCollection<string> portNameItems = new ObservableCollection<string>();

        [ObservableProperty]
        private string selectPortName;

        partial void OnSelectPortNameChanged(string value)
        {
            //WeakReferenceMessenger.Default.Send<MessageInfo, string>(
            //    new MessageInfo { message = value != null },
            //    "Main"
            //);
        }

        public bool JudgePowerIsAlarm()
        {
            if (PowerCurrentGet > PowerUpperLimit || PowerCurrentGet < PowerLowerLimit)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 开始监测
        /// True表示开启，false表示关闭
        /// </summary>
        [ObservableProperty]
        private bool isStartMonitoring;

        /// <summary>
        /// 功率上限值
        /// </summary>
        [ObservableProperty]
        private double powerUpperLimit;
        /// <summary>
        /// 功率下限值
        /// </summary>
        [ObservableProperty]
        private double powerLowerLimit;
        /// <summary>
        /// 当前功率读取值（功率计）
        /// </summary>
        [ObservableProperty]
        private double powerCurrentGet;

        #endregion

    }
}
